<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>主页</title>
</head>
<body>
	<%
		Integer num = (Integer)application.getAttribute("num");
		if (num == null) {
			// 初始化
			num = 0;
		} 
		//if (session.getAttribute("flag") == null) {
			//session.setAttribute("flag", "xx");
			//++num;
		//}
		// 另外一种方法替代,isNew()表示session是否是新的
		if (session.isNew()) {
			++num;
		}
	%>
		<div>共有<%= num %>人在线</div>
	<%
		application.setAttribute("num", num);
	%>
</body>
</html>